package com.yang.Service;


import com.yang.mapper.ProductMapper;
import com.yang.pojo.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper mapper;

    @Override
    public Double findTurnover() {
        // 获取当前日期，并格式化
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return mapper.selectTurnover(sdf.format(date));
    }

    @Override
    public List<Product> findAllProducts() {
        return mapper.selectAllProducts();
    }

    @Override
    public List<Product> findProductsByName(String name) {
        return mapper.selectProductsByName(name);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveProduct(Product product) {
        mapper.insertProduct(product);
    }
}
